﻿using System;

namespace Ooaavee.TestTools
{
    /// <summary>
    /// This is the base class for test hook attributes. 
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
    public abstract class TestHookDefinitionAttribute : Attribute
    {
        private int _order = int.MaxValue;

        /// <summary>
        /// Initializes a new instance of the TestHookDefinitionAttribute class.
        /// </summary>
        /// <param name="interfaceType">test hook interface type</param>
        /// <param name="parameters">test hook parameters</param>
        protected TestHookDefinitionAttribute(Type interfaceType, params object[] parameters)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }

            InterfaceType = interfaceType;
            Parameters = parameters;
        }

        /// <summary>
        /// Test hook interface type.
        /// </summary>
        public Type InterfaceType { set; get; }

        /// <summary>
        /// Test hook parameters.
        /// </summary>
        public object[] Parameters { set; get; }

        /// <summary>
        /// Test hook category.
        /// </summary>
        public abstract TestHookCategory Category { get; }

        /// <summary>
        /// The execute and dispose order of the test hooks.
        /// </summary>
        public int Order
        {
            get { return _order; }
            set
            {
                if (value < 0)
                {
                    throw new ArgumentOutOfRangeException("value", value, "Order must be >= 0.");
                }
                _order = value;
            }
        }
    }
}